package pl.ptemich.tankwars.objects;

import java.util.Random;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

public class CanonBall {

  /**
   *  
   */
  private static Image ballImage;

  /**
   * mass in kilograms
   */
  private float mass = 1;
  
  private float force = 10;
  
  private static final float MAX_SPEED_X = 0.4f;
  
  private static final float MAX_SPEED_Y = 0.8f;
  
  private static final int BALL_RADIUS = 5;
  
  private int fieldWidth;
  
  private int fieldHeight;  
  
  private float posX;
  
  private float posY;
  
  private float oldBallPosX = 10;
  
  private float oldBallPosY = 10;
  
  private float speedX;
  
  private float speedY;  
  
  public CanonBall(int fieldWidth, int fieldHeight) throws SlickException {
    this.fieldWidth = fieldWidth;
    this.fieldHeight = fieldHeight; 
    
    Random rand = new Random();
    posX = Double.valueOf(fieldWidth * Math.sin(rand.nextDouble())).floatValue();
    posY = Double.valueOf(fieldHeight * Math.sin(rand.nextDouble())).floatValue();
    
    speedX = Double.valueOf(MAX_SPEED_X * Math.sin(rand.nextDouble())).floatValue();
    speedY = Double.valueOf(MAX_SPEED_Y * Math.sin(rand.nextDouble())).floatValue();
    
    if (ballImage == null) {
      ballImage = new Image("resources/images/ball.png");
    }
  }
  
  public void render(Graphics graphics)
      throws SlickException {
    ballImage.draw(posX - BALL_RADIUS, posY - BALL_RADIUS);
  }  
  
  public void update(int delta) {
    posX = posX + speedX * delta;
    speedX = speedX + (force / mass) * delta;
    //t = t + dt;
  }
  
}
